<?php

include("global.php");

$pagetitle=" - Administration - BBCode";
$links=" > Administration > BBCode";

include ("header.php");

include ("admin_header.php");

if($userloggedinarray[15]!=="administrator"){
   unset($tplcontent);
   $tplcontent['notice']="Must be logged in as administrator to use control panel!";
   echo template('notice',$tplcontent);
}else{

if(!$addbbcode&&!isset($editbbcode)&&!isset($deletebbcode)&!$addbbcode2&&!isset($editbbcode2)){
	unset($tplcontent);

 $bbcodearray=getdata("$configarray[5]/bbcode.php");

   for($n=0;$n<count($bbcodearray);$n++){
    $linearray=explode("\t",$bbcodearray[$n]);

    if(count($linearray)>1){

    $tplcontent['bbcode'].="<b>$linearray[0]</b>\n";
    $tplcontent['bbcode'].=" | <a href=\"admin_bbcode.php?editbbcode=$n\">Edit</a>";
    $tplcontent['bbcode'].=" | <a href=\"admin_bbcode.php?deletebbcode=$n\">Delete</a>";

    $tplcontent['bbcode'].="<br><br>";
    }

   }//end bbcode loop

  $tplcontent['addnew'].="<a href=\"admin_bbcode.php?addbbcode=1\">Add new</a>";

  echo template('adminbbcodeview',$tplcontent);

 }

 if(isset($editbbcode)){
 unset($tplcontent);

 $bbcodearray=getdata("$configarray[5]/bbcode.php");
 $linearray=explode("\t",$bbcodearray[$editbbcode]);

 $tplcontent['formheader'].="<form action=\"admin_bbcode.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"editbbcode2\" value=\"$editbbcode\" size=40>";

 $tplcontent['bbcodeid'].="$editbbcode";

 $linearray[0]=htmlentities($linearray[0]);
 $tplcontent['description'].="<input type=text name=\"bbcodedesc\" size=40 value=\"$linearray[0]\" class=\"forminput\"><br><br>";

 $tplcontent['tag'].="<input type=text name=\"bbcodetag\" size=40 value=\"$linearray[1]\" class=\"forminput\"><br><br>";

 if($linearray[2]=="on"){
 $tplcontent['parameter'].="<input type=checkbox name=\"bbcodeparamter\" class=\"forminput\" checked>";
 }else{
 $tplcontent['parameter'].="<input type=checkbox name=\"bbcodeparameter\" class=\"forminput\">";
 }

 $linearray[3]=htmlentities($linearray[3]);
 $tplcontent['html'].="<input type=text name=\"bbcodehtml\" size=100 value=\"".$linearray[3]."\" class=\"forminput\"><br><br>";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Update\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";
 
 echo template('adminbbcodeedit',$tplcontent);

 }

 if(isset($editbbcode2)){
 $bbcodedesc=stripslashes($bbcodedesc);
 $bbcodetag=stripslashes($bbcodetag);
 $bbcodehtml=stripslashes($bbcodehtml);
 writedata("$configarray[5]/bbcode.php","$bbcodedesc\t$bbcodetag\t$bbcodeparameter\t$bbcodehtml",$editbbcode2);

  unset($tplcontent);
  $tplcontent['notice'].="BBCode edited - <a href=\"admin_bbcode.php\">Back to listing</a>";
  echo template('notice',$tplcontent);
 }

 if($addbbcode=="1"){
 unset($tplcontent);

 $tplcontent['formheader'].="<form action=\"admin_bbcode.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"addbbcode\" value=\"2\" size=40>";

 $tplcontent['description'].="<input type=text name=\"bbcodedesc\" size=40 class=\"forminput\">";

 $tplcontent['tag'].="<input type=text name=\"bbcodetag\" size=40 class=\"forminput\">";

 $tplcontent['parameter'].="<input type=checkbox name=\"bbcodeparameter\" class=\"forminput\">";

 $tplcontent['html'].="<input type=text name=\"bbcodehtml\" size=40 class=\"forminput\">";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Add\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";

 echo template('adminbbcodeadd',$tplcontent);
 }

 if($addbbcode=="2"){
 $bbcodearray=getdata("$configarray[5]/bbcode.php");
 $end=count($bbcodearray);

 $bbcodedesc=stripslashes($bbcodedesc);
 $bbcodetag=stripslashes($bbcodetag);
 $bbcodehtml=stripslashes($bbcodehtml);
 writedata("$configarray[5]/bbcode.php","$bbcodedesc\t$bbcodetag\t$bbcodeparameter\t$bbcodehtml",$end);

  unset($tplcontent);
  $tplcontent['notice'].="BBCode added - <a href=\"admin_bbcode.php\">Back to listing</a>";
  echo template('notice',$tplcontent);

 }

 if(isset($deletebbcode)){
 deletedata("$configarray[5]/bbcode.php",$deletebbcode);

  unset($tplcontent);
  $tplcontent['notice'].="BBCode $deletebbcode deleted - <a href=\"admin_bbcode.php\">Back to listing</a>";
  echo template('notice',$tplcontent);

 }

}
include("admin_footer.php");

include("footer.php");

?>